package com.caterina.components;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.LayoutManager;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import modulesAPI.v2.Module;

import com.caterina.activityManager.CActivity;
import com.caterina.resources.CColors;

public class CPanel extends JPanel{
	public CPanel(){
		super();
		super.setBackground(CColors.PANEL_BACKGROUND);
		//super.setOpaque(false);
	}
	public void setEnabled(boolean enabled) {
	    super.setEnabled(enabled);
	    for (Component component : getComponents())
	        component.setEnabled(enabled);
	}
	public CPanel(Module<?> module){
		super();
		this.setLayout(new BorderLayout());
		this.add(new JScrollPane(module.getPanel()),BorderLayout.CENTER);
	}
	public void add(Module<?>module){
		super.add(module.getPanel());
	}
	public void add(Module<?>module,Object arg){
		super.add(module.getPanel(),arg);
	}
	public CPanel(LayoutManager layout){
		super(layout);
		super.setBackground(CColors.PANEL_BACKGROUND);
	}
	public CPanel(CActivity owner,CActivity activity){
		super(new BorderLayout());
		super.setBackground(CColors.PANEL_BACKGROUND);
		activity.setActivityManager(owner.getActivityManager());
		activity.onStart();
		super.add(activity,BorderLayout.CENTER);
	}
	public void setBackground(Color c){
		super.setBackground(c);
		super.setOpaque(true);
	}
	public void setForeground(Color color){
		super.setForeground(color);
		Component[] components=this.getComponents();
		for(Component c:components){
			if(c instanceof JLabel){ c.setForeground(color);}
		}
	}
	private static final long serialVersionUID = 1L;
}
